#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@File: drawer.py
@Author: lijk34925 
@Date: 2025/5/29 16:10
@desc: 请补充本模块功能说明
"""
from qturboframe.lib.webdriver import SeleniumError

from BladeFerm.Lib.Common import logger
from qturboframe.public_ui.base_element import BaseElement


class Drawer(BaseElement):
    def __init__(self, element_para, father=None, timeout=5):
        super().__init__(element_para, father, timeout)
        self.drawer = None
        if self.element:
            self.drawer = self.element
        else:
            drawers = father.find_elements_by_xpath('//div[@class="h-drawer-wrap"]')
            self.drawer = drawers[0] if drawers else None
        if not self.drawer:
            logger.error('drawer不存在')
            raise SeleniumError("drawer不存在")

    def close(self):
        if self.drawer:
            drawer_close = self.drawer.find_element_by_xpath('.//a[@class="h-drawer-close"]/i')
            drawer_close.click()
            logger.info('关闭drawer')
        else:
            logger.info('drawer不存在')

    def get_drawer_body(self):
        return self.drawer.find_element_by_xpath('.//div[@class="h-drawer-body"]')
